package com.activitycode.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.activitycode.datamodel.find.FindSearchEntity;
import com.duostec.zhuyue.pets.R;

public class FindSearchAdapter extends BaseAdapter {

	public Context context;
	private List<FindSearchEntity> infoList;
	public FindSearchAdapter adapter;

	public FindSearchAdapter(Context context, List<FindSearchEntity> infoList) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.infoList = infoList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infoList.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return infoList.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		FindSearchEntity entity = infoList.get(position);
		ViewHolder viewHolder;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.adapter_search, null);
			viewHolder = new ViewHolder();
			viewHolder.searchIcon = (ImageView) convertView
					.findViewById(R.id.search_image);
			viewHolder.searchType = (TextView) convertView
					.findViewById(R.id.search_text);
			viewHolder.searchContent = (TextView) convertView
					.findViewById(R.id.search_condition);
			viewHolder.searchArrow = (ImageView) convertView
					.findViewById(R.id.search_arrow_right);

			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if (position % 2 == 0) {
			convertView.setBackgroundColor(context.getResources().getColor(
					R.color.item_bg1));
		} else {
			convertView.setBackgroundColor(context.getResources().getColor(
					R.color.item_bg2));
		}
		
		viewHolder.searchIcon.setImageDrawable(context.getResources().getDrawable(entity.getSearchIcon()));
		viewHolder.searchType.setText(context.getResources().getString(entity.getSearchType()));
		viewHolder.searchContent.setText(entity.getSearchContent());
		viewHolder.searchArrow.setImageDrawable(context.getResources().getDrawable(entity.getSearchArrow()));
		return convertView;
	}

	public final static class ViewHolder {
		private ImageView searchIcon;
		private TextView searchType;
		private TextView searchContent;
		private ImageView searchArrow;
	}

}
